package ruifeng.zcj.dig.ui.base;

import android.os.CountDownTimer;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;

import butterknife.Bind;
import butterknife.OnClick;
import ruifeng.zcj.dig.R;
import ruifeng.zcj.dig.base.BaseShowHidActivity;
import ruifeng.zcj.dig.base.api.OSChinaApi;
import ruifeng.zcj.dig.ui.register.bean.Code;
import ruifeng.zcj.mybase.base.utils2.AbJsonUtil;
import ruifeng.zcj.mybase.base.utils2.StringUtils;

/**
 * 获取验证码
 * Created by Administrator on 2016/9/22 0022.
 */
public abstract class GetCodeActivity2 extends BaseShowHidActivity{

   /* protected TimeCount time;// 倒计时
    protected String user_tel;// 入力的电话
    *//*@Bind(R.id.forget_btn_get_code)
    protected TextView btnGetCode;


    @Bind(R.id.forget_et_mobile)
    protected EditText mRegisterEtMobile;*//*

    protected Code code;


    protected boolean checkFirstPhone() {
        // 检测是否有网络
        if (!isHasInternet()) {
            showSnackBar(getString(R.string.is_hasInternet));
            return false;
        }

        // 电话号码
        this.user_tel = this.mRegisterEtMobile.getText().toString().trim();
        if (!StringUtils.isMobileNo(user_tel)) {
            showSnackBar(getString(R.string.error_invalid_email));
            return false;
        }
        return true;
    }

    *//**
     * 获取验证码
     *//*
    public void getValidateCode() {
        if (checkFirstPhone()) {
            time.cancel();
            OSChinaApi.getCode(this.user_tel, codeType(), new RequestCallBack<String>() {
                @Override
                public void onSuccess(ResponseInfo<String> responseInfo) {
                    code = (Code) AbJsonUtil.fromJson(responseInfo.result, Code.class);
                    if (code.OK()) {
                        time.start();
                        showSnackBar("验证码:" + code.getCode());
                    }
                }

                @Override
                public void onFailure(HttpException e, String s) {

                }
            });
        }
    }


    *//**
     * 倒计时
     *//*
    public class TimeCount extends CountDownTimer {

        public TimeCount(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);// 参数依次为总时长,和计时的时间间隔
        }

        @Override
        public void onFinish() {// 计时完毕触发
            setGetCodeBtn(true);
            btnGetCode.setText(getString(R.string.register_get_validate_code));
        }

        @Override
        public void onTick(long millisUntilFinished) {// 计时过程显示
            setGetCodeBtn(false);
            btnGetCode.setTextColor(getResources().getColor(R.color.action_amber));
            btnGetCode.setText(String.valueOf((millisUntilFinished / 1000)));
        }
    }

    protected void setGetCodeBtn(boolean isEnabled) {
        this.btnGetCode.setEnabled(isEnabled);// 初始化时获取验证码按钮无效
        if (isEnabled) {
            this.btnGetCode.setTextColor(getResources().getColor(R.color.action_amber));
        } else {
            this.btnGetCode.setTextColor(getResources().getColor(android.R.color.black));
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (time != null) {
            time.cancel();
        }
    }

    *//**
     * 1:注册
     * 2：找回密码
     **//*
    public abstract String codeType();

*/

}
